from tornado.web import RequestHandler, Application, url
import tornado.ioloop


class MainHandler(RequestHandler):
    def get(self):
        self.write('<a href="%s">link to story</a>' %
                   self.reverse_url("story", "1"))


class StoryHandler(RequestHandler):
    def initialize(self, db):
        self.db = db

    def get(self, story_id):
        self.write("this is story %s" % story_id)


db = "123"
app = Application([
    url(r"/", MainHandler),
    url(r"/story/([0-9]+)", StoryHandler, dict(db=db), name="story")
])


def _test_application():
    """
    192.168.1.103:8000
    """
    app.listen(8000)
    tornado.ioloop.IOLoop.current().start()


if __name__ == '__main__':
    _test_application()
